package com.youan.pangu.security.configuration;

import com.youan.pangu.security.brower.controller.AuthenticationController;
import com.youan.pangu.security.brower.controller.ValidateCodeController;
import com.youan.pangu.security.brower.filter.ValidateCodeFilter;
import com.youan.pangu.security.brower.validatecode.ValidateCodeGenerator;
import com.youan.pangu.security.brower.validatecode.ValidateCodeProcessor;
import com.youan.pangu.security.brower.validatecode.ValidateCodeProcessorHolder;
import com.youan.pangu.security.brower.validatecode.img.ImageCodeGenerator;
import com.youan.pangu.security.brower.validatecode.img.ImageCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: 辛晟昊
 * @time: 2020/3/9 15:38
 */
@Configuration
public class SecurityBeanConfiguration {

    /**
     * 未登录时的处理方法
     * @return
     */
    @Bean
    public AuthenticationController authenticationController(){
        return new AuthenticationController();
    }

    @Bean
    public ValidateCodeController validateCodeController(){
        return new ValidateCodeController();
    }

    @Bean
    public ValidateCodeProcessorHolder validateCodeProcessorHolder(){
        return new ValidateCodeProcessorHolder();
    }

    @Autowired
    private ValidateCodeProcessor imageValidateCodeProcessor;

    @Bean
    public ValidateCodeProcessor imageValidateCodeProcessor(){
        return new ImageCodeProcessor();
    }

    @Bean
    public Map<String, ValidateCodeProcessor> validateCodeProcessors(){
        Map<String, ValidateCodeProcessor> result = new HashMap<>();
        result.put("imageValidateCodeProcessor", imageValidateCodeProcessor);
        return result;
    }

    @Bean
    public Map<String, ValidateCodeGenerator> validateCodeGenerators(){
        Map<String, ValidateCodeGenerator> result = new HashMap<>();
        result.put("imgCodeGenerator", new ImageCodeGenerator());
        return result;
    }

    @Bean
    public ValidateCodeFilter validateCodeFilter(){
        return new ValidateCodeFilter();
    }




}
